import static java.lang.Thread.sleep;

public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new MyThread2());
        thread.start();
        while (true) {
            System.out.println("main");
            sleep(1000);
        }
    }
}

class MyThread2 implements Runnable {
    public void run() {
        while (true) {
            System.out.println("MyThread2");
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}